home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 123 / cdrom123.iso / essenc / extens / wweb / Web Developer.xpi / chrome / webdeveloper.jar / content / webdeveloper / common.js next >
Encoding:
JavaScript  |  2004-11-21  |  1.6 KB  |  66 lines

  1. // Formats a file size
  2. function webdeveloper_formatFileSize(fileSize)
  3. {
  4.     const stringBundle = document.getElementById("webdeveloper-string-bundle");
  5.  
  6.     // If the file size is set
  7.     if(fileSize)
  8.     {
  9.         // If the file size is greater than a kilobyte
  10.         if(fileSize > 1024)
  11.         {
  12.             return Math.round(fileSize / 1024) + " " + stringBundle.getString("webdeveloper_kilobytes");
  13.         }
  14.         else
  15.         {
  16.             return fileSize + " " + stringBundle.getString("webdeveloper_bytes");
  17.         }
  18.     }
  19.     else
  20.     {
  21.         return "";
  22.     }
  23. }
  24.  
  25. // Removes all child nodes from a node
  26. function webdeveloper_removeAllChildNodes(node)
  27. {
  28.     const childNodes = node.childNodes;
  29.  
  30.     // Loop through the child nodes
  31.     for(var i = 0; i < childNodes.length; i++)
  32.     {
  33.         node.removeChild(childNodes[i]);
  34.     }
  35. }
  36.  
  37. // Removes a substring from a string
  38. function webdeveloper_removeSubstring(string, substring)
  39. {
  40.     // If the string was not empty
  41.     if(string)
  42.     {
  43.         const substringStart = string.indexOf(substring);
  44.  
  45.         // If the substring was found in the string
  46.         if(substring && substringStart != -1)
  47.         {
  48.             return string.substring(0, substringStart) + string.substring(substringStart + substring.length, string.length);
  49.         }
  50.         else
  51.         {
  52.             return string;
  53.         }
  54.     }
  55.     else
  56.     {
  57.         return "";
  58.     }
  59. }
  60.  
  61. // Trims leading and trailing spaces from a string
  62. String.prototype.trim = function()
  63. {
  64.     return this.replace(new RegExp("^\\s+|\\s+$", "gi"), "");
  65. }
  66.